package com.dao.imp;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;

import com.dao.RoomStatusDao;
import com.dao.core.DaoBaseImp;
import com.pojo.RoomStatus;

public class RoomStatusDaoImp extends DaoBaseImp<RoomStatus> implements RoomStatusDao{

	@Override
	public RoomStatus getRoomStatus(Integer statusId) {
		
		return (RoomStatus)getSession().get(RoomStatus.class, statusId);
	
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<RoomStatus> getRoomStatusBydate(Date beginDate, Date endDate) {
		String hql ="from RoomStatus as rs where rs.beginDate <= :endDate and rs.endDate >= :beginDate";
		Query query = getSession().createQuery(hql);
		query.setDate("beginDate", beginDate);
		query.setDate("endDate", endDate);
		List<RoomStatus> list = query.list();
		return list;
	}

	@Override
	public void addRoomStatus(RoomStatus roomStatus) {
		getSession().save(roomStatus);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<RoomStatus> getRoomStatusByDateAndRoomId(Date beginDate,
			Date endDate, Integer roomId) {
		String hql ="from RoomStatus as rs where rs.beginDate <= :endDate and rs.endDate >= :beginDate and rs.RoomId=:roomId";
		Query query = getSession().createQuery(hql);
		query.setDate("beginDate", beginDate);
		query.setDate("endDate", endDate);
		query.setInteger("roomId", roomId);
		List<RoomStatus> list = query.list();
		return list;

	}

}
